# -*- coding: utf-8 -*-
'''
Created on 2013-5-3

@author: dyq
'''
from Common.htmlHlep import Find
from Common.tool import tool
from Cms import config
from Cms.plus import  page,user
from Models import  models
import  hashlib,datetime,random
from django.db import transaction


@page.page_render(user.Admin())
def Index(request):
        '''
                            列表页
        '''
        info=models.Sys_Log()
        return Find.View(request,info)
    
    
@page.page_render(user.Admin())
def List(request):
        '''
                            列表页
        '''
        typeId=int(request.POST.get("TypeId",-1))
        openTime=request.POST.get("openTime","")
        endTime=request.POST.get("endTime","")
        nickName=request.POST.get("NickName","")
        list=models.Sys_Log.objects.all()
        if nickName!="":
            
            userinfoList=models.User_Account.objects.filter(NickName=nickName)
            if len(userinfoList)!=0:
                list= list.filter(UserId=userinfoList)
            else:
                list= list.filter(UserId='_')
        
        if typeId!=-1:
            list= list.filter(TypeId=typeId)
            
        if openTime!="" and endTime!="":
            list= list.filter(LogTime__gte=datetime.datetime.strptime(openTime,'%Y-%m-%d')).filter(LogTime__lte=datetime.datetime.strptime(endTime,'%Y-%m-%d'))              

        list=list.order_by("-LogTime") #倒序加上-号
        
        return Find.View(request,Find.paginator(request,list))
    
@page.page_render(user.Admin())
def View(request):
        '''
                            查看
        '''
        info =models.Sys_Log.objects.get(LogId=request.GET.get("LogId"))
        
        return Find.View(request,info)
